package logic

import (
	"context"
	"house_srv/house"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewHouseUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseUpdateLogic {
	return &HouseUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *HouseUpdateLogic) HouseUpdate(req *types.HouseUpdateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	update, err := l.svcCtx.HouseSrv.HouseUpdate(l.ctx, &house.HouseUpdateRequest{
		HouseId:     req.HouseId,
		UserId:      req.UserId,
		HouseName:   req.HouseName,
		HousePrice:  req.HousePrice,
		Floor:       req.Floor,
		Acreage:     req.Acreage,
		Address:     req.Address,
		HouseType:   req.HouseType,
		HouseStatus: req.HouseStatus,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "房源修改成功",
		Data: map[string]interface{}{
			"Update": update.HouseId,
		},
	}, nil
}
